<!DOCTYPE html>
<html>
<head>
  <title>zip.js test</title>
  <meta charset="utf-8">
  <script type="text/javascript" src="../jquery.min.js"></script>
  <script type="text/javascript" src="base64.js"></script>
  <script type="text/javascript" src="rawdeflate.min.js"></script>
  <script type="text/javascript" src="rawinflate.min.js"></script>
  <script type="text/javascript" src="inflate.min.js"></script>
  <script type="text/javascript" src="deflate.min.js"></script>
  <script type="text/javascript" src="zlib.min.js"></script>
  <script type="text/javascript" src="gzip.min.js"></script>
  <script type="text/javascript" src="gunzip.min.js"></script>
  <!-- <script type="text/javascript" src="unzip.min.js"></script> -->
</head>
<body>

</body>
<script type="text/javascript">
  
// var originStr = "eJy9Ow1vG0d2f4URcEeuuJR3dpefFokud0mT1pJUSFqUdDocjMZpD3A+4CTIXQX/GCN3ce7itucPxo4d27Eby3ZjnZKeLSWXAEKRXJE2Li4QAtdNc0Xfm6+d/aCls3A1LO7s+5o38968efOGXJ066v/0xWNTldSPfjQ1pRu6bZbtcqFolvM6+bHOYIVy0CbFQsFmr+8+HL+PIMsyy5Zl6CYC7/6JUhWKhJStPIMhxMwrAolZIPlCyVAggiHoNG8KgvUra2t3z975emObIfJhOvm68eU7v5zSyyrrxpcff89ACtV4HUEhjSYLTXiNcJrqQJLmLwn2JBmTXy9th3i3vqJzZxkw/0UO2zyNsBIpFAqC7OIFSmbbJatQLCqTHoOE2OKyI9psnj5/q2TMlH8QUgqhBTJT+sHuI3vSJEjcqFWMmWsPL6NWaUovJPvzHowtHRc8s1g0yS7mfEoviHS9i+ShN78oF4uyfAoBRFU7RJM0kKeD7Mlof/aaijnKnhfgHswRiRF/hTBE/1ifOjp/9MRRDH/Y/mv3pecwFk5t/PuN784/uvJfUwjsHn2BAvHleee55xadn/30FWQxZkBM8AcSnkfUwtHjrx1LwCt0x19+5e+8Y88Pf/YqCl45sfJi16lUB8O+6wwzbq9rQjOz1HD6uqHp6dQH/5FKaweRbClO1ul1hy1Gd/+moOvH6TxniVHdeSCoBoclFX90HX3J0fRU32EU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zBy8COO3dwiv2wq3Xs+Mv892L4ij8we+HQaz8PgV555fWXTjzHQS+KH5V1X3sBQAZC4G3485eP8Vfv2PHBq0dffQ1/dmYWTGIXEHji6Osd9oO1PDEB0Dx+9G9+snDsBP3tmY6/M3sRf9zLpBaRBXUJOhkce5W3eFckD+3l+uBvX3p9ccBRy/XFAQrG15P/B0UYhss=";

var originStr = "eMKcBcKAQQkAAAzChMK6w5jDrWAPYcO9f8OCTcKfAAlSAlk=";
var url = "data:text/json;base64," + originStr;

var reader = new FileReader();

reader.addEventListener("loadend", function() {
  // reader.result contains the contents of blob as a typed array
  debugger;
  var str = ab2str(reader.result);
  var compressed = reader.result;
  // var inflate = new Zlib.Unzip(compressed);
  var gunzip = new Zlib.Gunzip(compressed);
  var plain = gunzip.decompress();
});

fetch(url)
.then(function(res) {
  // return res.blob();
  return res.text();
  // return res.arrayBuffer();
})
// .then(function(blob) {
.then(function(text) {

  debugger;
  // 这里把 text 转成 Uint8Array
  var buf = str2ab(text);
  // var gunzip = new Zlib.Gunzip(buf);
  // var plain = gunzip.decompress();
  var inflate = new Zlib.Inflate(buf);
  var plain = inflate.decompress();
  console.log(ab2str(plain));
  // reader.readAsArrayBuffer(blob);
  // var inflate = new Zlib.Inflate(blob);
  // var plain = inflate.decompress();
});

function ab2str(buf) {
  return String.fromCharCode.apply(null, new Uint8Array(buf));
}

function str2ab(str) {

  var buf = new Uint8Array(str.length);
  for(var i = 0; i < str.length; i++) {
    buf[i] = str.charCodeAt(i);
  }

  return buf;
}

// ------------test--------------------
// debugger;

function b64EncodeUnicode(str) {
    // first we use encodeURIComponent to get percent-encoded UTF-8,
    // then we convert the percent encodings into raw bytes which
    // can be fed into btoa.
    return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
        function toSolidBytes(match, p1) {
            return String.fromCharCode('0x' + p1);
    }));
}

function b64DecodeUnicode(str) {
    // Going backwards: from bytestream, to percent-encoding, to original string.
    return decodeURIComponent(atob(str).split('').map(function(c) {
        return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
    }).join(''));
}

// var debug = "{\"hello\": \"world\"}";
// var debug = "hello";
// var debugArr = str2ab(JSON.stringify(debug));
var debug = "jdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdgajdskljalkdfjalsdga";
var debugArr = str2ab(debug);
console.log(debugArr);

var deflate = new Zlib.RawDeflate(debugArr);
var zipArr = deflate.compress();
console.log(zipArr);

var gzip = new Zlib.Gzip(debugArr);
var zipArr = gzip.compress();
console.log(zipArr);

var deflate = new Zlib.Deflate(debugArr);
var zipArr = deflate.compress();

console.log(zipArr);

console.log(doEncode(ab2str(zipArr)));

console.log(b64EncodeUnicode(ab2str(zipArr)));

// var gunzip = new Zlib.Gunzip(zipArr);
// var plain = gunzip.decompress();


// var arr = new Uint8Array([11,12]);
// var gzip = new Zlib.Gzip(arr);
// var zipStr = gzip.compress();
// var gunzip = new Zlib.Gunzip(zipStr);
// var plain = gunzip.decompress();
// debugger;
</script>
</html>